{include file="Public:header2"/}
<body style="min-height: 100%;background-color: #fff">
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <form onsubmit="return false;">
                        <div class="layui-form" wid100 lay-filter="">
                            <div class="layui-form-item">
                                <label class="layui-form-label">抽卡机名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" value="{$info.title}" autocomplete="off" class="layui-input" style="width: 521px" disabled>
                                </div>
                            </div>
                            <!--<div class="layui-form-item">-->
                            <!--    <label class="layui-form-label">赠送编码</label>-->
                            <!--    <div class="layui-input-inline">-->
                            <!--        <input type="text" name="card_no" autocomplete="off"  placeholder="请输入赠送编号" class="layui-input" style="width: 521px">-->
                            <!--    </div>-->
                            <!--</div>-->
                            <div class="layui-form-item">
                                <label class="layui-form-label">卡名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="title" autocomplete="off"  placeholder="请输入奖品名称" class="layui-input" style="width: 521px">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">卡等级</label>
                                <div class="layui-input-inline">
                                    <select name="shang_id">
                                        <option  value="">--请选择--</option>
                                        {foreach name="shang" item="vo"}
                                        <option value="{$vo.id}">{$vo.title}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">卡售价</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="price"  autocomplete="off"  placeholder="请输入奖品售价" class="layui-input">
                                </div>
                                <label class="layui-form-label">兑换价格</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="money"  autocomplete="off"  placeholder="请输入兑换价格" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">卡数量</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="special_stock" value="-100" autocomplete="off" placeholder="请输入奖品数量" class="layui-input"  style="width: 521px">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">等级内概率</label>
                                <div class="layui-input-inline" style="width: 700px">
                                    <input type="text" name="real_pro" autocomplete="off" placeholder="请输入等级内概率" class="layui-input"  style="width: 521px;display: inline-block">%
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">卡类型</label>
                                <div class="layui-input-inline" style="width: 512px;">
                                    <input type="radio"  lay-filter="goods_type"  name="goods_type" value="1" title="现货" checked="" >
                                    <input type="radio"  lay-filter="goods_type"  name="goods_type" value="2" title="预售">
                                </div>
                            </div>
                            <div class="layui-form-item sale_time" style="display: none">
                                <label class="layui-form-label">预售时间</label>
                                <div class="layui-input-inline" style="width: 512px;">
                                    <input type="text" name="sale_time" id="sale_time" placeholder="请选择预售时间" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">排序</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="sort" value="0" autocomplete="off"placeholder="请输入排序" class="layui-input"  style="width: 521px">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">卡图片</label>
                                <div class="layui-input-inline">
                                    <input type="hidden" name="imgurl" value="" lay-verify="required" placeholder="请上传图片" autocomplete="off" class="layui-input" >
                                    <img style="float:left;width:120px;" class="" id="imgurl" src="/static/image/upload.jpg">
                                </div>
                            </div>
                            <input type="hidden" name="card_id" value="{$info.id}">
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" onclick="return check()">确认保存</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="Public:footer"/}
</body>
</html>
<script type="text/javascript">
    layui.use(['layer','form','upload','element','laydate'], function(){
        var $ = layui.$;
        var form = layui.form;
        var upload = layui.upload;
        var element = layui.element;
        var laydate = layui.laydate;
        var new_data = new Date();
        new_data.setTime(new_data.getTime()+24*60*60*1000);
        var tomorrow_time = new_data.getFullYear()+"-" + (new_data.getMonth()+1) + "-" + new_data.getDate();
        laydate.render({
            elem: '#sale_time',
            min:tomorrow_time
        });
        //现货/预售切换
        form.on('radio(goods_type)', function (data) {
            var value = data.value;   //  当前选中的value值
            if(value == 1){
                $("#sale_time").val('')
                $(".sale_time").hide()
            }else{
                $(".sale_time").show()
            }
        });
        upload.render({
            accept:'imgurl'
            ,elem: '#imgurl' //绑定元素
            ,url: '/admin/picture' //上传接口
            ,done: function(res){
                //上传完毕回调
                if(res.status == 1){ //成功
                    layer.msg("上传成功",{icon:1,time:1000},function(){
                        $("#imgurl").attr("src",res.data.path);  //单图
                        $("input[name=imgurl]").val(res.data.imgurl);
                    });
                }else{ //失败
                    layer.msg(res.msg,{icon:2,anim:6,time:1500});
                }
            }
            ,error: function(){
                //请求异常回调
                layer.msg('服务繁忙，请稍后再试',{icon:2,anim:6,time:1500});
            }
        });

    });

    function check(){
        var url="{:url('/admin/card_goodslist_add')}";
        var $ = layui.$;
        var load=layer.load(2);
        $.post(url,$("form").serialize(),function(data){
            if(data.status==1){
                layer.msg(data.msg,{icon:1,time:1500},function(){
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index);
                    parent.location.reload();
                });
            }else{
                layer.msg(data.msg,{icon:2,anim:6,time:1500},function(){
                    layer.close(load);
                });
            }
        })
    }


</script>
